/*
 * AnalyzeCharges.h
 *
 *  Created on: May 26, 2011
 *      Author: marchi
 */

#ifndef ANALYZECHARGES_H_
#define ANALYZECHARGES_H_

#include <iostream>
#include "Metric.h"
#include "RhoAvg.h"
#include "CellSymmetry.h"

static Rho * ro=NULL;
static int nframes=0;
static CellSymmetry * symmetry=NULL;
static int AnalyzeCharges(t_topology *top, t_trxframe *fr, t_pbc *pbc,
              int nr, gmx_ana_selection_t *sel[], void *data)
{
    /* Here, you can do whatever analysis your program requires for a frame. */

    RhoAvg ** roavg0=static_cast<RhoAvg **>(data);
    RhoAvg * & roavg=*roavg0;
    if(!symmetry) symmetry=new CellSymmetry(top,fr,pbc);
    if(!ro) {
    	ro=new Rho [ngrps];
    	ro[Slt].Allocate();
    	ro[Sol].Allocate();
    	ro[Tot].Allocate();
    }
    symmetry->Center();
    symmetry->Fit();

    Metric Met;
    Met(SuperCO);

    for(int i=0;i<ngrps;i++)
    	chg[i].setCoord(Met,fr->x,cidx[i]);

	ro[Slt].Density(chg[Slt]);
	ro[Sol].Density(chg[Sol]);
	ro[Tot]=ro[Slt]+ro[Sol];

	roavg[Slt].Accumulate(ro[Slt]);
	roavg[Sol].Accumulate(ro[Sol]);
	roavg[Tot].Accumulate(ro[Tot]);
	nframes++;
    return 0;
}


#endif /* ANALYZECHARGES_H_ */
